All Questions
167 questions
4votes
2answers
121views
Optimal multiplication of two 3D arrays having a variable dimension
I would like to multiply tensors R = {R_1, R_2, ..., R_M} and X = {X_1, X_2, ..., X_M} where R_i and X_i are 3×3 and 3×N_i matrices, respectively. How can I make maximum use of NumPy functionalities ...
0votes
1answer
520views
How to understand transpose operation on a 3D or Higher Dimensional Array
Consider a 3D array array_3d with shape (3, 2, 2): array_3d = np.array([ [[ 0, 1], [ 2, 3]], [[ 4, 5], [ 6, 7]], [[ 8, 9], [10, 11]] ]) array_3d.shape = (3, 2, 2) ...
2votes
3answers
86views
Numpy slicing on a zero-padded 2D array
Given a 2D Numpy array, I'd like to be able to pad it on the left, right, top, bottom side, like the following pseudo-code. Is there anything like this already built into Numpy? import numpy as np a =...
0votes
1answer
64views
NumPy ndarray non contiguous memory layout
I need some help in understanding the equations involved in finding the index of an element in an ndarray. I have been reading the Book "Guide to NumPy" by Travis A Oliphant. Link to the ...
0votes
1answer
74views
Fix this numpy-function so it accepts multidimensional inputs
I am trying to compute the following function: geo-decay-function: in numpy, has to be vectorized. The catch in this case is that it should work for multidimensional inputs. E.g., x having dimensions ...
0votes
2answers
84views
Finding the maximum value in a specific axis of a 3D array for each group of values on the axis
I have a 3D numpy array of shape (8, x, y) where x and y can be any integer value from 0 to ~500. These 8 "layers" of shape (x, y) each represent a possible z value at a specific point on a ...
0votes
1answer
32views
Rewriting numpy function to handle 2d and 3d inputs
I am trying to rewrite an numpy function such that it can deal with 2d and 3d inputs. Consider the following code: import numpy as np def adstock_geometric(x: np.array, theta: np.array): x_decayed ...
0votes
1answer
126views
Mean absolute value along all columns of a 3D Numpy array
I always get find myself in state of confusion when dealing with a multi-dimensional array. Imaging having the following array of arrays, where each array contains feature importance scores (3-...
0votes
1answer
97views
Numpy comparing nested arrays
I am considering arrays of shape (n,2) for arbitrary n. I want to check whether the two-element sub-arrays match. As an example: import numpy as np a=np.array([[1,0],[2,0]]) b=np.array([[1,0],[2,0]]) ...
0votes
1answer
69views
Multiplying 2D matrices to get a 3D matrix
I have two matrices A and B of dimensions (n_m, n_u) and (n_m, n). I want a 3D matrix with dimensions (n, n_m, n_u) such that the first column of B is multiplied (element-wise) with every column of A ...
1vote
1answer
130views
How does ndarray.__new__ know from where it is being called?
In the numpy documentation of subclassing ndarray here. It is said that ndarray.__new__, passes __array_finalize__ the new object, of our own class (self) as well as the object from which the view ...
0votes
1answer
221views
Numpy append not adding new row despite axis specification
I'm new to numpy and I'm trying to create add a new row. I'm reading that I just need to specify the axis. Right now I'm just testing import numpy as np arr = np.array(['1', '2', '3']) print(np....
0votes
2answers
120views
Python empty numpy 2D array and append value
Problem I wanna make size undefined 2D empty numpy array and append values. my try import numpy as np import randrom unknown = random.randint(2, 666) #arr = np.array([np.array([])]) #arr = np.empty((...
3votes
3answers
857views
Remove borders of a n-dimensional numpy array
I am trying to replace all the values of the border of my n-dimensional array by False. So far, I have seen that numpy provides np.pad that allows me to grow an array in all dimensions with an ...
0votes
0answers
31views
Selecting Array Values With A Separate Array of Indices
I am attempting to index a stacked 3-D Numpy array (named stack) by a group of 2-D indices contained inside of a separate Numpy array (named piece). The separate array contains several groups of 2-D ...